package com.sjf.day01;

import sun.misc.ThreadGroupUtils;
import sun.nio.ch.ThreadPool;

import java.util.concurrent.*;

/**
 * @author <sjf753@qq.com>
 * @since 2021/12/13 13:15
 **/
public class MutliThread {

    public static volatile int i = 0;
    //新建线程池
   public static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
            5,
            10,
            0,
            TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(),
            Executors.defaultThreadFactory(),
            new ThreadPoolExecutor.AbortPolicy()
    );

    public static void main(String[] args) {
        Task task = new Task();
        for (int i = 0; i < 10; i++) {
            threadPool.execute(task);
        }
    }

   static class Task implements Runnable{
       @Override
       public synchronized void run() {
               //try {
               //    TimeUnit.SECONDS.sleep(1);
               //} catch (InterruptedException e) {
               //    e.printStackTrace();
               //}
               System.out.println(Thread.currentThread().getName()+"执行了"+i++);
       }
   }
}
